﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DC2010_Editor.Controls.Utils;
using DC2010.Objects;

namespace DC2010.Tools
{
    public partial class InventoryTextBox : UserControl
    {
        private IList<string> itemList { get; set; }

        public InventoryTextBox()
        {
            InitializeComponent();
        }

        public void SetRelatedObject(IList<string> itemList)
        {
            this.itemList = itemList;

            if (itemList != null)
            {
                PromptText = string.Format("Total: {0} items in inventory", itemList.Count);
            }
            else
            {
                PromptText = string.Format("inventory is empty.");
            }
        }

        private void textBox1_MouseHover(object sender, EventArgs e)
        {
            textBox1.BackColor = Color.FromArgb(212, 255, 212);
        }

        private void textBox1_MouseLeave(object sender, EventArgs e)
        {
            textBox1.BackColor = Color.FromArgb(192, 255, 192); ;
        }

        private void textBox1_Click(object sender, EventArgs e)
        {
            string FormattedInput = "";
            foreach (string s in itemList)
            {
                FormattedInput += s + ";";
            }

            if (FormattedInput.Length >0)
                FormattedInput = FormattedInput.Substring(0, FormattedInput.Length - 1);

            ListCreator lc = new ListCreator(FormattedInput);
            lc.ShowDialog();

            string[] sField = lc.Result.Split(';');
            itemList.Clear();

            foreach (string s in sField)
            {
                string sx = s.Replace(";", "");
                itemList.Add(sx);
            }

            if (itemList != null)
            {
                PromptText = string.Format("Total: {0} items in inventory", itemList.Count);
            }
            else
            {
                PromptText = string.Format("inventory is empty.");
            }


        }

        public string InnerText
        {
            get
            {
                return textBox1.Text;
            }
            set
            {
                textBox1.Text = value;
            }
        }

        public string PromptText
        {
            get
            {
                return textBox1.PromptText;
            }
            set
            {
                textBox1.PromptText = value;
            }
        }
    }
}
